import * as user from '@/api/user.js'
	export default {
		name: "contacts",
		data() {
			return {
				tips: 60, 
				tipsShow: false,//验证码送后倒计时
				value: '',
				code: ''
			};
		},
		watch: {
		  value(newValue, oldValue) {
		  }
		},
		onLoad() {
		},
		onShow() {
		},
		methods: {
			getCodeBnt() {
				if(!this.value) {
					this.$tools.toast('请输入手机号')
					return
				}
				if (!this.tipsShow) {
				  // 模拟向后端请求验证码
				  uni.showLoading({
					title: '正在获取验证码'
				  })
				  user.phoneGetCode({phone: this.value}).then(res=>{
					  uni.hideLoading();
					  this.$tools.toast('验证码已发送');
					  var timeoutId = setInterval(res=>{
						  this.tipsShow = true
						  this.tips = this.tips -1
						  if(this.tips == 0) {
							  clearTimeout(timeoutId)
							  this.tipsShow = false
							  this.tips = 60
						  }
					  },1000)
				  })
				} else {
				  this.$tools.toast('倒计时结束后再发送');
				}
			},
			change(e) {
				console.log('change', e);
			},
			// 保存手机号
			saveBnt() {
				if(!this.value) {
					this.$tools.toast('请输入手机号');
					return
				}
				if(!this.code) {
					this.$tools.toast('请输入验证码');
					return
				}
				user.savePhone({phone: this.value,code: this.code}).then(res=>{
					uni.navigateBack({
						data:1
					})
				})
			}
		}
	}